
package GUI;

import v3.Sauvegarde1;
import Kernel.Billet;
import Kernel.HtmlBillet;
import Kernel.Trajet;


public class Bilan extends javax.swing.JFrame {
    

	private static final long serialVersionUID = 1L;
	private Billet b;
	
	
    /** Crée une nouvelle instance de Bilan */
    public Bilan() {
        initComponents();
        this.b = new Billet();
        this.setLocationRelativeTo(this.getParent());
    }
    
    /**
     *  Crée une nouvelle instance de Bilan paramétrée
     * @param t représente le trajet précédemment sélectionné
     * @param b représente le billet créé à partir des options précédentes
     */
    public Bilan(Trajet t, Billet b){
    	initComponents();
    	this.b = b;
        this.jTextArea_recapB.setText(b.toString());
        this.jTextArea_recapB.setEditable(false);
        double def = b.prixDefinitif();
        Double tmp = new Double(def);
        String prix = tmp.toString();
        this.jTextField_tarif.setText(prix);
        this.jTextField_tarif.setEditable(false);
        this.jTextArea_recapT.setText(t.toString());
        this.jTextArea_recapT.setEditable(false);
        this.setLocationRelativeTo(this.getParent());
        
    }
    
    /**
	 * Initialisation des composants d'AWT.
	 */	                    
    private void initComponents() {

        jLabel_bilan = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea_recapB = new javax.swing.JTextArea();
        jLabel_tarif = new javax.swing.JLabel();
        jTextField_tarif = new javax.swing.JTextField();
        jButton_valider = new javax.swing.JButton();
        jButton_retour = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea_recapT = new javax.swing.JTextArea();
        jLabel_recapB = new javax.swing.JLabel();
        jLabel_recapT = new javax.swing.JLabel();
        jButton_deco = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel_bilan.setText("Bilan");

        jTextArea_recapB.setColumns(20);
        jTextArea_recapB.setRows(5);
        jScrollPane1.setViewportView(jTextArea_recapB);

        jLabel_tarif.setText("Prix :");

        jButton_valider.setText("Valider");
        jButton_valider.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_validerActionPerformed(evt);
            }
        });

        jButton_retour.setText("Retour");
        jButton_retour.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_retourActionPerformed(evt);
            }
        });

        jTextArea_recapT.setColumns(20);
        jTextArea_recapT.setRows(5);
        jScrollPane2.setViewportView(jTextArea_recapT);

        jLabel_recapB.setText("Récapitulatif Billet :");

        jLabel_recapT.setText("Récapitulatif Trajet :");

        jButton_deco.setText("Déconnexion");
        jButton_deco.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_decoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel_tarif)
                            .addGap(18, 18, 18)
                            .addComponent(jTextField_tarif, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 124, Short.MAX_VALUE)
                            .addComponent(jButton_deco)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jButton_retour)
                            .addGap(18, 18, 18)
                            .addComponent(jButton_valider)
                            .addGap(41, 41, 41))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel_bilan)
                            .addContainerGap(518, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel_recapB))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel_recapT)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel_bilan)
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_recapB)
                    .addComponent(jLabel_recapT))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane2)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel_tarif)
                            .addComponent(jTextField_tarif, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(31, 31, 31))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton_deco)
                            .addComponent(jButton_retour)
                            .addComponent(jButton_valider))
                        .addGap(21, 21, 21))))
        );

        pack();
    }               

    private void jButton_retourActionPerformed(java.awt.event.ActionEvent evt) {
    	Utilisateur.client.supprimerBillet(b);
    	Etape11 e = new Etape11();
        this.setVisible(false);
        e.setVisible(true);
        this.dispose();
    }       
    
    private void jButton_validerActionPerformed(java.awt.event.ActionEvent evt) {
    	Utilisateur.client.getServeur().ajouterBillet(b);
    	HtmlBillet html = new HtmlBillet(b);
   	 	html.generationHtml();
   	 	try {
   	 		Sauvegarde1.encodeToFile(Accueil.serveur,"Sauvegarde-Serveur.xml");
   	 		System.out.println(Accueil.versionUtilisation);
        
   	 	} catch(Exception e) {
   	 		e.printStackTrace();
   	 	}
    }

    private void jButton_decoActionPerformed(java.awt.event.ActionEvent evt) {
    	Accueil ac = new Accueil();
        this.setVisible(false);
        ac.setVisible(true);
        this.dispose();
    }
    
    
                   
    private javax.swing.JButton jButton_deco;
    private javax.swing.JButton jButton_retour;
    private javax.swing.JButton jButton_valider;
    private javax.swing.JLabel jLabel_bilan;
    private javax.swing.JLabel jLabel_recapB;
    private javax.swing.JLabel jLabel_recapT;
    private javax.swing.JLabel jLabel_tarif;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea_recapB;
    private javax.swing.JTextArea jTextArea_recapT;
    private javax.swing.JTextField jTextField_tarif;
    
}
